﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace NotificationPusher
{
	public class MainPageViewModel : INotifyPropertyChanged
	{
		private string _subscriptionUrl;
		public string SubscriptionUrl
		{
			get
			{
				return _subscriptionUrl;
			}
			set
			{
				_subscriptionUrl = value;
				OnPropertyChanged("SubscriptionUrl");
			}
		}

		private string _title;
		public string Title
		{
			get
			{
				return _title;
			}
			set
			{
				_title = value;
				OnPropertyChanged("Title");
			}
		}

		private string _message;
		public string Message
		{
			get
			{
				return _message;
			}
			set
			{
				_message = value;
				OnPropertyChanged("Message");
			}
		}

		private string _status;
		public string Status
		{
			get
			{
				return _status;
			}
			set
			{
				_status = value;
				OnPropertyChanged("Status");
			}
		}

		private void OnPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}
		public event PropertyChangedEventHandler PropertyChanged;

		internal void SendNotification()
		{
			NotificationServiceReference.NotificationServiceClient client =
				new NotificationServiceReference.NotificationServiceClient();
			client.SendToastNotificationCompleted += (se, ea) =>
				{
					if (ea.Error != null)
					{
						Status = "Unhandled Error";
						return;
					}

					Status = ea.Result;
				};
			client.SendToastNotificationAsync(
				SubscriptionUrl,
				Title,
				Message);
		}
	}
}
